package com.ruoyi.factorydata.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.factorydata.domain.PurchaseOrderInfo;
import com.ruoyi.factorydata.service.IPurchaseOrderInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购单信息Controller
 * 
 * @author ruoyi
 * @date 2025-07-17
 */
@RestController
@RequestMapping("/warehouse/purchaseOrderInfo")
public class PurchaseOrderInfoController extends BaseController
{
    @Autowired
    private IPurchaseOrderInfoService purchaseOrderInfoService;

    /**
     * 查询采购单信息列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:purchaseOrderInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(PurchaseOrderInfo purchaseOrderInfo)
    {
        startPage();
        List<PurchaseOrderInfo> list = purchaseOrderInfoService.selectPurchaseOrderInfoList(purchaseOrderInfo);
        return getDataTable(list);
    }

    /**
     * 导出采购单信息列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:purchaseOrderInfo:export')")
    @Log(title = "采购单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseOrderInfo purchaseOrderInfo)
    {
        List<PurchaseOrderInfo> list = purchaseOrderInfoService.selectPurchaseOrderInfoList(purchaseOrderInfo);
        ExcelUtil<PurchaseOrderInfo> util = new ExcelUtil<PurchaseOrderInfo>(PurchaseOrderInfo.class);
        util.exportExcel(response, list, "采购单信息数据");
    }

    /**
     * 获取采购单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:purchaseOrderInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(purchaseOrderInfoService.selectPurchaseOrderInfoById(id));
    }

    /**
     * 新增采购单信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:purchaseOrderInfo:add')")
    @Log(title = "采购单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseOrderInfo purchaseOrderInfo)
    {
        return toAjax(purchaseOrderInfoService.insertPurchaseOrderInfo(purchaseOrderInfo));
    }

    /**
     * 修改采购单信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:purchaseOrderInfo:edit')")
    @Log(title = "采购单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseOrderInfo purchaseOrderInfo)
    {
        return toAjax(purchaseOrderInfoService.updatePurchaseOrderInfo(purchaseOrderInfo));
    }

    /**
     * 删除采购单信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:purchaseOrderInfo:remove')")
    @Log(title = "采购单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(purchaseOrderInfoService.deletePurchaseOrderInfoByIds(ids));
    }

    /**
     * 修改采购单信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:purchaseOrderInfo:auth')")
    @Log(title = "采购单审核", businessType = BusinessType.UPDATE)
    @PutMapping("auth")
    public AjaxResult auth(@RequestBody PurchaseOrderInfo purchaseOrderInfo)
    {
        return toAjax(purchaseOrderInfoService.auth(purchaseOrderInfo));
    }

}
